/**
 *Copyright (c) 2024 watereyes
 * workflow is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.workflow.api.rule;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import org.koron.ebs.mybatis.SessionFactory;

import com.koron.workflow.api.rule.FilterRuleStrategy;
import com.koron.workflow.common.bean.StaffBean;

/**
 * 不选择制单人
 * @author bin
 *
 */
public class FilterRuleStrategy3 implements FilterRuleStrategy{

	@Override
	public List<StaffBean> filter(SessionFactory factory, List<StaffBean> staffs, StaffBean initiator, int autoPicker) {
		staffs = staffs.stream().filter(t -> t != null).filter(t -> !Objects.equals(t.getAccount(), initiator.getAccount())).collect(Collectors.toList());
		// 假如自动选人规则为：发起人
		if(autoPicker == 1 && staffs.contains(initiator)) {
			return Arrays.asList(initiator);
		}
		// 假如自动选人规则为：直属上司
		if(autoPicker == 2) {
			return Arrays.asList(initiator);
		}
		return staffs;
	}
}
